package com.example.geange.demo01;


import android.app.ProgressDialog;
import android.os.Bundle;
import android.app.Fragment;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;


/**
 * A simple {@link Fragment} subclass.
 */
public class webview_news extends Fragment {

    private String url ;
    private WebView webView;
    private ProgressDialog dialog;
    private View view;

    public webview_news(String url) {
        this.url = url;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_webview_news, container, false);
        init();
        return view;
    }

    private void init() {

        webView = (WebView) view.findViewById(R.id.webview);

        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(false);
        if (!MainActivity.loadpic) {
            settings.setBlockNetworkImage(true);
        }

        settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
//        webView.setBackgroundColor(MainActivity.webBackground);
        webView.getBackground().setAlpha(255);

        webView.loadUrl(url);
        webView.setWebViewClient(new WebViewClient(){
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                //返回值是true的时候控制网页在WebView中去打开，如果为false调用系统浏览器或第三方浏览器去打开
                view.loadUrl(url);
                return true;
            }

        });
    }
}
